package com.test.dababy.dababy_06_loan_apply;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.test.dababy.R;
import com.test.dababy.dababy_01_launcher.Base_dababyApplication;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

public class LoanApplyDetail {



    private String scAi="";
    private double yF6q=0.4933371214378699;
    private char tOmU='J';
    private int bAzR=219;
    private char pilA='a';
    private String x31w="";

    public void svoG4(){
        new Thread(() -> {
            try {

                if (TextUtils.isEmpty(getScAi())) setScAi(String.valueOf(getyF6q())+gettOmU()+getbAzR());
                else setX31w(String.valueOf(getPilA()));

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setScAi(String scAi) {
        this.scAi = scAi;
    }

    public void setyF6q(double yF6q) {
        this.yF6q = yF6q;
    }

    public void settOmU(char tOmU) {
        this.tOmU = tOmU;
    }

    public void setbAzR(int bAzR) {
        this.bAzR = bAzR;
    }

    public void setPilA(char pilA) {
        this.pilA = pilA;
    }

    public void setX31w(String x31w) {
        this.x31w = x31w;
    }

    public String getScAi() {
        return scAi;
    }

    public double getyF6q() {
        return yF6q;
    }

    public char gettOmU() {
        return tOmU;
    }

    public int getbAzR() {
        return bAzR;
    }

    public char getPilA() {
        return pilA;
    }

    public String getX31w() {
        return x31w;
    }

    private static class Inner_dababy {
        private static LoanApplyDetail instance_dababy = new LoanApplyDetail();
    }

    private LoanApplyDetail() {}

    public static LoanApplyDetail getInstance_dababy() {
        return Inner_dababy.instance_dababy;
    }

    public static void parse_dababy(JSONObject obj) {
        Inner_dababy.instance_dababy = new Gson().fromJson(obj.toString(), LoanApplyDetail.class);

        Inner_dababy.instance_dababy.detailItemList.clear();
        JSONArray param = obj.optJSONArray("detailItemList");
        Gson gson = new Gson();
        if (param!=null){
            for (int i=0;i<param.length();i++){
                try {
                    Inner_dababy.instance_dababy.detailItemList.add(gson.fromJson(param.optString(i), LnoaAp_dababyl_dababyyItem.class));
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }

    }

    private String repayAmount;
    private String realAmount;
    private String processingVatFee;
    private String repayProVatFee;
    private String currency;
    private String repayProFee;
    private String bankAccount;//尼日、乌干达、肯尼亚
    private String overdueRate;
    private String interest;
    private String amount;
    private String processingFee;
    private String walletMobile;//加纳
    private String days;


    //申请页显示配置信息
    private final ArrayList<LnoaAp_dababyl_dababyyItem> detailItemList = new ArrayList<>();

    public String getRpAmount_dababy() {
        if (TextUtils.isEmpty(repayAmount)) return "";
        return repayAmount;
    }

    public String getRealAmount_dababy() {
        if (TextUtils.isEmpty(realAmount)) return "";
        return realAmount;
    }

    public String getProcessingVatFee_dababy() {
        if (TextUtils.isEmpty(processingVatFee)) return "";
        return processingVatFee;
    }

    public String getRpProVatFee_dababy() {
        if (TextUtils.isEmpty(repayProVatFee)) return "";
        return repayProVatFee;
    }

    public String getCurrency_dababy() {
        if (TextUtils.isEmpty(currency)) {
            svoG4();
            return "";
        }
        return currency;
    }

    public String getRpProFee_dababy() {
        if (TextUtils.isEmpty(repayProFee)) return "";
        return repayProFee;
    }

    public String getBkAccount_NiUgKe_dababy() {
        if (TextUtils.isEmpty(bankAccount)) return "";
        return bankAccount;
    }

    public Double getOvduRate_dababy() {

        if (TextUtils.isEmpty(overdueRate)) return 0d;

        try {
            return Double.parseDouble(overdueRate)*100;
        }catch (NumberFormatException e){
            e.printStackTrace();
            return 0d;
        }

    }

    public String getInterest_dababy() {
        if (TextUtils.isEmpty(interest)) return "";
        return interest;
    }

    public String getAmount_dababy() {
        if (TextUtils.isEmpty(amount)) return "";
        return amount;
    }

    public String getProcessingFee_dababy() {
        if (TextUtils.isEmpty(processingFee)) return "";
        return processingFee;
    }

    public String getWltMobile_Gh_dababy() {
        if (TextUtils.isEmpty(walletMobile)) return "";
        return walletMobile;
    }

    public String getDays_dababy() {
        if (TextUtils.isEmpty(days)) return "";
        return days;
    }

    public String getTermStr_dababy(){

        try {
            int dayInt = Integer.parseInt(days);
            if (dayInt <= 1) return Base_dababyApplication.getInstant().getString(R.string.day,dayInt);
            else return Base_dababyApplication.getInstant().getString(R.string.days,dayInt);
        }catch (NumberFormatException e){
            e.printStackTrace();
            return Base_dababyApplication.getInstant().getString(R.string.day,0);
        }

    }

    public ArrayList<LnoaAp_dababyl_dababyyItem> getDetailItemList_dababy() {
        return detailItemList;
    }

}
